package com.sky.mapper;

import com.sky.entity.User;
import com.sky.entity.UserReport;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {
    @Select("select * from user where openid = #{openid}")
    User selectByOpenId(String openid);

    Long insert(User user);

    @Select("select * from user where id = #{id}")
    User getById(Long id);

    /**
     * 按照创建日期分组查询新增用户数
     * @param begin
     * @param end
     * @return
     */
    List<UserReport> countNewUserGroupByCreateTime(LocalDate begin, LocalDate end);


    /**
     * 按照日期查询总用户数
     * @param date
     * @return
     */
    Integer countTotalUserByCreateTime(LocalDate date);

    /**
     * 查询某一天的新增用户数
     * @param date
     * @return
     */
    @Select("select count(*) from user where date(create_time) = #{date}")
    Integer countNewUserByCreateTime(LocalDate date);

    /**
     * 根据map条件查询新增用户数
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
